/**********************************************************************
 * SailmiPIM - modular cross-platform feature Personal Information Manager Tools.
 * Copyright(C) 2006-2014  Georg Rudoy
 *
 * Distributed under the Boost Software License, Version 1.0.
 *(See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
 **********************************************************************/

#pragma once

#include <QNetworkAccessManager>
#include "sailmipim/core/ihookproxy.h"

class QTimer;

namespace SailmiPIM
{
	namespace Util
	{
		class CustomCookieJar;
	}

	class NetworkAccessManager : public QNetworkAccessManager
	{
		Q_OBJECT

		std::unique_ptr<Util::CustomCookieJar> CookieJar_;
	public:
		explicit NetworkAccessManager(QObject* = nullptr);
		~NetworkAccessManager() override;
	protected:
		QNetworkReply* createRequest(Operation, const QNetworkRequest&, QIODevice*) override;
	private:
		void SaveCookies() const;
	signals:
		void requestCreated(QNetworkAccessManager::Operation,
				const QNetworkRequest&, QNetworkReply*);

		void hookNAMCreateRequest(SailmiPIM::IHookProxy_ptr proxy,
					QNetworkAccessManager *manager,
					QNetworkAccessManager::Operation *op,
					QIODevice **dev);
	};
};
